/*
  THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
  ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED
  TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
  PARTICULAR PURPOSE.

  Copyright (c) 2006-2009 PRO ACTIVE SAS - www.proactive-group.com
   
  Ref_UsbEnum.c
  -------------

  This is the reference applications that shows how to list USB devices
  (work on Windows with FTDI FTD2XX driver only)
  
  JDA 19/06/2006 : initial release

*/
#include "products/springprox/springprox.h"

#include <stdio.h>
#include <string.h>

int main(int argc, char **argv)
{
#ifdef WIN32
  SWORD rc;
  DWORD count;
  DWORD idx;
  char s_buffer[64];
  char device[64], description[64];

  printf("SpringCard SDK for K531/SpringProx-CF/CSB Legacy\n");
  printf("\n");
  printf("USB ENUMERATION of CSB4 or compliant devices\n");
  printf("--------------------------------------------\n");
  printf("www.springcard.com\n\n");

  rc = SPROX_GetLibrary(s_buffer, sizeof(s_buffer));
  if (rc != MI_OK)
  {
    printf("Failed to get API version\n");
    return 0;
  }
  printf("API version : %s\n", s_buffer);
  printf("\n");

  /* Main loop */
  /* --------- */

  count = 0;
  for (idx = 0; ; idx++)
  {
    rc = SPROX_EnumUSBDevices(idx, device, description);
    if (rc != MI_OK)
      break;
    printf("Found device USB%d\n", idx + 1);
    printf("\tIdentifier  = %s\n", device);
    printf("\tDescription = %s\n", description);
    count++;
  }

  if (count)
  {
    printf("Total : %d device(s) found\n", count);
  } else
  {
    printf("No device found\n");
  }

#else

  printf("The SPROX_EnumUSBDevices function is only available on Windows\n");
  printf("Linux: try sprox_usb_enum instead.\n");  

#endif

  return 0;
}
